package lu.med.praxiswahl.wahlumed.client.analysenintern;


import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableColumn;
import lu.med.praxiswahl.wahlumed.client.utilities.ColumnWidthControler;
import lu.med.praxiswahl.wahlumed.client.wclient.Main;

/**
 * 
 * @author Lars Holger Roth
 */
@SuppressWarnings("serial")
public class AnalysenInternTable extends JTable {

	private TableColumn column;
	private ColumnWidthControler c;
	private boolean isColumnWidthChanged;
	private TableColumn resizedColumn;

	public AnalysenInternTable(AnalysenInternDataModel model, Main dataManager) {
		super(model);
		this.setRowHeight(30);
		this.setTableHeader(tableHeader);
		this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		// this.setAutoResizeMode(AUTO_RESIZE_OFF);
		this.selectionModel = getSelectionModel();
		this.selectionModel
				.addListSelectionListener(new AnalysenInternTableSelectionListener(
						model));
		this.setDefaultRenderer(Object.class, new AnalysenInternCellRenderer(
				model, dataManager));
		this.setDefaultEditor(Object.class, new AnalysenInternCellEditor(model,
				dataManager));

		column = null;

		c = new ColumnWidthControler(
				Main.COLUMNWIDTH_CONFIGURATION_FILE, "analyseInterntbl", this);

		for (int i = 0; i < 14; i++) {
			column = this.getColumnModel().getColumn(i);
			column.setPreferredWidth(c.getColumnWidth(i));
		}

		this.getColumnModel().addColumnModelListener(new TableColumnWidthListener(this));
		this.getTableHeader().addMouseListener(new TableHeaderMouseListener(this, c));
		
	}
	
	public boolean getColumnWidthChanged() {
        return isColumnWidthChanged;
    }

    public void setColumnWidthChanged(boolean widthChanged, TableColumn resizedColumn) {
        isColumnWidthChanged = widthChanged;
        this.resizedColumn = resizedColumn;
    }

	public TableColumn getResizedColumn() {
		return resizedColumn;
	}

	@Override
	 public void changeSelection(final int row, final int column, boolean toggle, boolean extend)
    {
        super.changeSelection(row, column, toggle, extend);
        editCellAt(row, column);
        transferFocus();
    }
}
